package com.scs.application.modules.wm.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.query.QueryContext;
import com.scs.application.core.query.QueryContextHolder;
import com.scs.application.modules.sys.model.PageResult;
import com.google.common.collect.Maps;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.wm.service.PickItemService;
import com.scs.application.modules.wm.entity.PickItem;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 科室请领单明细 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/wm/pick_item")
public class PickItemController extends CrudController<PickItemService, PickItem>{


    /**
     * 科室退货获取库存耗材数据列表
     */
    @GetMapping("/pageDeptReturn")
    public PageResult pageDeptReturn(@RequestParam Map<String, Object> reqData) {
        Map<String, Object> userParam = null;

        if (reqData.containsKey("userParam")) {
            JSONObject ob = JSON.parseObject(reqData.get("userParam") + "");
            userParam = Maps.newHashMap(ob);
        }else {
            userParam = new HashMap<>();
            userParam.put("deptId", null);
            userParam.put("deptReturnId", null);
        }
        QueryContext queryContext = QueryContextHolder.currentContext();

        IPage pageResult = service.pageDeptReturn(queryContext, userParam);
        return PageResult.ok("查询成功", pageResult.getRecords(), pageResult.getTotal());
    }

}
